package com.xqit.ydzhkt.answer.controller;

import com.github.pagehelper.PageHelper;
import com.xqit.ydzhkt.answer.mapper.ListAnswerMapper;
import com.xqit.ydzhkt.answer.mapper.QueryQuestionTitleMapper;
import com.xqit.ydzhkt.answer.mapper.TestMapper;
import com.xqit.ydzhkt.answer.service.ListAnswerService;
import com.xqit.ydzhkt.entity.AnswerEntity;
import com.xqit.ydzhkt.entity.QuestionEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by Janus on 2020/6/9
 */
@RestController
@RequestMapping("/listAnswer")
@Api(tags = "查看回答")
public class ListAnswerController {
    @Autowired
    private ListAnswerService listAnswerService;
    @GetMapping("/listAllAnswer")
    @ApiOperation("查看某个问题和回答")
    public QuestionEntity listAnswer(@RequestParam("id")int id,
                                     @RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum,
                                     @RequestParam(defaultValue = "2",value = "pageSize") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        QuestionEntity s = listAnswerService.listAnswer(id,pageNum,pageSize);

        return s;
    }

//    @Autowired
//    private QueryQuestionTitleMapper queryQuestionTitleMapper;
//    @GetMapping("query")
//    @ApiOperation("查看问题标题和描述")
//    public QuestionEntity query(int id){
//       QuestionEntity x = queryQuestionTitleMapper.queryQuestionContent(id);
//        return x;
//    }

//    @Autowired
//    private ListAnswerMapper listAnswerMapper;
//    @GetMapping("query")
//    @ApiOperation("根据问题id查看问题回答")
//    public List<AnswerEntity> list2(int id){
//        List<AnswerEntity> sq = listAnswerMapper.listAnswer(id);
//        return sq;
//    }

    // test
        @Autowired
    private TestMapper testMapper;
    @GetMapping("test")
    @ApiOperation("测试一对多")
    public QuestionEntity query(int id){
        QuestionEntity qq = testMapper.listQuestionAnswer(id);
        return qq;

    }

}
